package com.aidong.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import com.aidong.activity.entity.Member;

/**
 * list对象集合排序
 * 
 * @param resultMap
 */
public class SortUtil {

	/**
	 * 活动距离排序
	 * 
	 * @param resultMap
	 */
	public static void distanceSort(List<Map<String, Object>> resultMap) {

		Collections.sort(resultMap, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				if (Integer.parseInt(o1.get("count").toString()) > Integer
						.parseInt(o2.get("count").toString())) {
					return 1;
				}
				if (Integer.parseInt(o1.get("count").toString()) == Integer
						.parseInt(o2.get("count").toString())) {
					return 0;
				}
				return -1;
			}

		});
	}

	/**
	 * 预约状态排序
	 * 
	 * @param resultMap
	 */
	public static void appointStatusSort(List<Map<String, Object>> resultMap) {

		Collections.sort(resultMap, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				if (Integer.parseInt(o1.get("status").toString()) > Integer
						.parseInt(o2.get("status").toString())) {
					return 1;
				}
				if (Integer.parseInt(o1.get("status").toString()) == Integer
						.parseInt(o2.get("status").toString())) {
					return 0;
				}
				return -1;
			}

		});
	}

	/**
	 * 活动状态排序
	 * 
	 * @param resultMap
	 */
	public static void activeStatusSort(List<Map<String, Object>> resultMap) {

		Collections.sort(resultMap, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				if (Integer.parseInt(o1.get("oderBy").toString()) > Integer
						.parseInt(o2.get("oderBy").toString())) {
					return 1;
				}
				if (Integer.parseInt(o1.get("oderBy").toString()) == Integer
						.parseInt(o2.get("oderBy").toString())) {
					return 0;
				}
				return -1;
			}

		});
	}

	/**
	 * 附近的人排序
	 * 
	 * @param resultMap
	 */
	public static void nearbySort(List<Map<String, Object>> resultMap) {

		Collections.sort(resultMap, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				if (Integer.parseInt(o1.get("distance").toString()) > Integer
						.parseInt(o2.get("distance").toString())) {
					return 1;
				}
				if (Integer.parseInt(o1.get("distance").toString()) == Integer
						.parseInt(o2.get("distance").toString())) {
					return 0;
				}
				return -1;
			}

		});
	}
	
	/**
	 * 关注列表排序
	 * 
	 * @param resultMap
	 */
	public static void attionbySort(List<Member> members) {

		Collections.sort(members, new Comparator<Member>() {

			@Override
			public int compare(Member o1, Member o2) {
				if (o1.getDistance() > o2.getDistance()) {
					return 1;
				}
				if (o1.getDistance() == o2.getDistance()) {
					return 0;
				}
				return -1;
			}

		});
	}

	/**
	 * 运动圈热度排序
	 * 
	 * @param resultMap
	 */
	public static void contentHotSort(List<Map<String, Object>> resultMap) {

		Collections.sort(resultMap, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				if (Integer.parseInt(o1.get("count").toString()) < Integer
						.parseInt(o2.get("count").toString())) {
					return 1;
				}
				if (Integer.parseInt(o1.get("count").toString()) == Integer
						.parseInt(o2.get("count").toString())) {
					return 0;
				}
				return -1;
			}

		});
	}
}
